package com.huawei.hiveFunctions;

import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;

/**
 * @author liucheng
 * @since 0.1 2023-11-11 16:47
 **/
public class UDFLowerOrUpperCase extends UDF {
    public Text evaluate(Text text) {
        return this.evaluate(text, "lower");
    }

    public Text evaluate(Text text, String lowerOrUpper) {
        if (text == null) {
            return null;
        }
        if ("lower".equals(lowerOrUpper)) {
            return  new Text(text.toString().toLowerCase());
        } else if ("upper".equals(lowerOrUpper)) {
            return new Text(text.toString().toUpperCase());
        }
        return text;
    }
}
